# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery
  self.allow_forgery_protection = false
  layout "main"
  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
  
  ensure_authenticated_to_facebook
  rescue_from Facebooker::Session::SessionExpired, :with => :facebook_session_expired
  before_filter :save_user
  
  def facebook_session_expired
    clear_fb_cookies!
    clear_facebook_session_information
    #flash[:error] = "Your facebook session has expired."
    redirect_to root_url
  end
  
  def save_user
    @facebook_user = facebook_session.user
    @user = User.find_or_create(@facebook_user) unless @facebook_user.nil?
    if @user.is_new_user
      redirect_to step_one_steps_url
    end
  end
  
end
